<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax测试</title>
</head>
<body>

                <button type="button" onclick="testGet1();">测试Get1</button>
       
                <button type="button" onclick="testGet2();">测试Get2</button>

                <button type="button" onclick="testGet3();">测试Get3</button>

                <button type="button" onclick="testGet4();">测试Get4</button>
                
                <button type="button" onclick="testGet5();">测试Get5</button>
       

    <div id="name1">
    
    </div>
    <div id="from">

    </div>
    <div id="title">

    </div>
    <div id="content">

    </div>
    <div id="authors">

    </div>
</body>
<script type="text/javascript">
    // 测试Get1
   function testGet1(){
       var name=document.getElementById('name1');
       var ajax =new XMLHttpRequest();
       ajax.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=李白');
       ajax.send();
       ajax.onreadystatechange =function(){
           if (ajax.readyState==4 && ajax.status ==200) {
               var obj =JSON.parse(ajax.responseText);
               if (obj.code ==200 && obj.message =='成功!') {
                name.innerText =obj.result.name;
                console.log(obj.result);  
               }
           }
       }
   }
 
//  测试Get2
function testGet2(){
  var name =document.getElementById('name1');
  var from =document.getElementById('from');
  var ajax =new XMLHttpRequest();
  ajax.open('GET','http://poetry.apiopen.top/sentences');
  ajax.send();
  ajax.onreadystatechange=function(){
      if (ajax.readyState==4 && ajax.status ==200) {
          var obj =JSON.parse(ajax.responseText);
          if (obj.code ==200 && obj.message =='成功!') {
              name.innerText =obj.result.name;
              from.innerText =obj.result.from;
              console.log(obj.result);
          }
      }
  }

}
// 测试Get3
function testGet3(){
    var title =document.getElementById('title');
    var content =document.getElementById('content');
    var authors =document.getElementById('authors');
    var ajax =new XMLHttpRequest();
    ajax.open('GET','https://api.apiopen.top/getSongPoetry');
    ajax.send();
    ajax.onreadystatechange=function(){
        if (ajax.readyState ==4 && ajax.status ==200) {
            var obj =JSON.parse(ajax.responseText);
            if (obj.code ==200 && obj.message =='成功!') {
                title.innerText =obj.result.title;
               content.innerText =obj.result.content;
               authors.innerText =obj.result.authors;
                console.log(obj.result);
            }
        }
    }
}
</script>
</html>